﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;

using ZhimeiSoft.Framework.Server.Base;
using ZhimeiSoft.CharmManager.DOL;
using ZhimeiSoft.CharmManager.Server.DAL.Interface;

namespace ZhimeiSoft.CharmManager.Server.DAL
{
    public class CustomerServiceItemReservationTimeDAL: BaseDal, ICustomerServiceItemReservationTimeDAL
    {
        private void AddInParameters(ref DbCommand cmd, DBEntityCustomerServiceItemReservationTime detail)
        {
            if (detail == null)
                return;

            DB.AddInParameter(cmd, DBEntityCustomerServiceItemReservationTime.FieldName.CSEQNUM, DbType.Int32, detail.CSEQNUM);
            DB.AddInParameter(cmd, DBEntityCustomerServiceItemReservationTime.FieldName.CDAYS, DbType.Int32, detail.CDAYS);
            DB.AddInParameter(cmd, DBEntityCustomerServiceItemReservationTime.FieldName.CMEMO, DbType.String, detail.CMEMO);
            DB.AddInParameter(cmd, DBEntityCustomerServiceItemReservationTime.FieldName.CUSTOMERSERVICEITEMID, DbType.Int32, detail.CUSTOMERSERVICEITEMID);
        }

        public void InsertCustomerServiceItemDetail(DBEntityCustomerServiceItemReservationTime detail)
        {
            string strSQL = CustomerServiceItemReservationTimeDAL_Const.SQL_INSERT_CUSTOMERSERVICEITEMDETAIL;
            DbCommand cmd = DB.GetSqlStringCommand(strSQL);
            AddInParameters(ref cmd, detail);
            DB.ExecuteNonQuery(cmd);
        }

        public void UpdateCustomerServiceItemDetail(DBEntityCustomerServiceItemReservationTime detail)
        {
            string strSQL = CustomerServiceItemReservationTimeDAL_Const.SQL_UPDATE_CUSTOMERSERVICEITEMDETAIL;
            DbCommand cmd = DB.GetSqlStringCommand(strSQL);
            AddInParameters(ref cmd, detail);
            DB.AddInParameter(cmd, DBEntityCustomerServiceItemReservationTime.FieldName.CUSTOMERSERVICEITEMDETAILID, DbType.Int32, detail.CUSTOMERSERVICEITEMDETAILID);
            DB.ExecuteNonQuery(cmd);
        }

        public void DeleteCustomerServiceItemDetail(string sFilter)
        {
            string strSQL = CustomerServiceItemReservationTimeDAL_Const.SQL_DELETE_CUSTOMERSERVICEITEMDETAIL;
            if (sFilter.Trim() != string.Empty)
                strSQL += " WHERE " + sFilter;

            DbCommand cmd = DB.GetSqlStringCommand(strSQL);
            DB.ExecuteNonQuery(cmd);
        }

        public DataSet QueryCustomerServiceItemDetail(string sFilter)
        {
            string strSQL = CustomerServiceItemReservationTimeDAL_Const.SQL_QUERY_CUSTOMERSERVICEITEMDETAIL;
            if (sFilter != string.Empty)
                strSQL += " WHERE " + sFilter;

            DbCommand cmd = DB.GetSqlStringCommand(strSQL);
            return DB.ExecuteDataSet(cmd);
        }



        public void SubmitCustomerServiceItmeReservationTime(DataSet ds)
        {
            DBEntityCustomerServiceItemReservationTime detail = new DBEntityCustomerServiceItemReservationTime();
            this.UpdateDataSet(ds, detail.GetTableName());
        }
    }
}
